#define _CRT_SECURE_NO_WARNINGS 1
#include"queue.h"
void init_queue(h_t* q)
{
	assert(q);
	q->head = NULL;
	q->tail = NULL;
	q->sz = 0;
}
void push_queue(h_t* q, QueDateType x)
{
	assert(q);
	Quenode* newnode=(Quenode*)malloc(sizeof(Quenode));
	newnode->data = x;
	newnode->next = NULL;
	if (newnode == NULL)
	{
		perror("push_queue");
		exit(-1);
	}
	if (q->head == NULL)
	{
		q->head = q->tail = newnode;
	}
	else
	{
		q->tail->next = newnode;
		q->tail = newnode;
	}
	q->sz++;
}
void pop_queue(h_t* q)
{
	assert(q);
	assert(!empty_queue(q));
	if (q->head->next==NULL)
	{
		free(q->head);
		q->head = NULL;
		q->tail = NULL;
	}
	else
	{
		Quenode* next = q->head->next;
		free(q->head);
		q->head = next;
	}
	q->sz--;
}
QueDateType queue_front(h_t* q)
{
	assert(q);
	assert(!empty_queue(q));
	return q->head->data;
}
QueDateType queue_back(h_t* q)
{
	assert(q);
	assert(!empty_queue(q));
	return q->tail->data;
}
bool empty_queue(h_t* q)
{
	assert(q);
	return q->head == NULL;
}
int size_queue(h_t* q)
{
	assert(q);
	return q->sz;
}
void destroy_queue(h_t* q)
{
	assert(q);
	Quenode* cur = q->head;
	while (cur)
	{
		Quenode* next = cur->next;
		free(cur);
		cur = next;
	}
}